package by.hatton.engine.processor;

import by.hatton.engine.bo.BaseRequestDataWrapper;
import android.os.Bundle;
import android.os.ResultReceiver;

public abstract class BaseProcessor implements IProcessor {

	public static final int START = 0;
	public static final int FINISH = 1;
	public static final int ERROR = 2;
	public static final int IN_PROGRESS = 3;
	
	private ResultReceiver mResultReceiver;
	private BaseRequestDataWrapper mBaseWrapper;

	public BaseProcessor(ResultReceiver mResultReceiver, BaseRequestDataWrapper mBaseWrapper) {
		this.mResultReceiver = mResultReceiver;
		this.mBaseWrapper = mBaseWrapper;
	}

	public void start() {
		try {
			sendMessage(START, null);
			executeProcess();
		} catch (Exception e) {
			Bundle errorData = new Bundle();
			errorData.putSerializable("error", e);
			sendMessage(ERROR, errorData);
		}
	}

	public void sendMessage(int statusCode, Bundle data) {
		mResultReceiver.send(statusCode, data);
	}

	public BaseRequestDataWrapper getmBaseWrapper() {
		return mBaseWrapper;
	}

	public void setBaseWrapper(BaseRequestDataWrapper baseWrapper) {
		this.mBaseWrapper = baseWrapper;
	}
	
}